package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    /**
     * 插入收货地址
     * @param addressBook
     */
    void insert(AddressBook addressBook);

    /**
     * 动态条件查询
     * @param addressBook
     * @return
     */
    List<AddressBook> selectAllByUserId(AddressBook addressBook);

    /**
     * 更新操作
     * @param addressBook
     */
    void update(AddressBook addressBook);

    @Update("update address_book set is_default = 0 where user_id=#{userId}")
    void setIsDefaultIsFalse(Long userId);

    @Delete("delete from address_book where id = #{id}")
    void delete(Long id);

    @Select("select * from address_book where id = #{id}")
    AddressBook selectById(Long id);
}
